<?php
	class Order_course_auths extends CI_Model{

	 	function __construct(){
          	parent::__construct();
      	}

       

        function get_order_record_codes($data_id, $data_type, $status = 0, $code = 0){
            if($data_type > 0 && $data_type < 4){
                $sql = "SELECT c.*,u.name FROM {$this->db->dbprefix}o2o_school_system_video_course_codes AS c ";
                $where = "WHERE c.course_id = '{$data_id}' ";
            }elseif($data_type == 4){
                $sql = "SELECT c.*,u.name FROM {$this->db->dbprefix}o2o_school_system_topic_codes AS c ";
                $where = "WHERE c.subject_id = '{$data_id}' ";
            }elseif($data_type == 5){
                $sql = "SELECT c.*,u.name FROM {$this->db->dbprefix}o2o_school_system_shixun_codes AS c ";
                $where = "WHERE c.sx_id = '{$data_id}' ";
            }elseif($data_type == 6){
                $sql = "SELECT c.*,u.name FROM {$this->db->dbprefix}o2o_school_video_user_codes AS c ";
                $where = "WHERE c.sx_id = '{$data_id}' ";
            }
            if($status > 0){
                $where .= " AND c.status = $status ";
            }
            if(!empty($code)){
                $where .= " AND c.code = '{$code}' ";
            }
            $sql .= "LEFT JOIN {$this->db->dbprefix}o2o_student AS u ON(u.user_id=c.use_uid) $where ORDER BY c.status ASC";
            
            $result = $this->db->query($sql)->result_array();
            return $result; 
        }
	}